using System;
using System.Collections.Generic;
using System.Text;
using IdSharp.Tagging.ID3v2;
using IdSharp.Tagging.ID3v1;

namespace Media_Renamer {
    public class MP3File {
        private String m_filePath;

        private String m_filename;

        private IID3v2 m_Id3v2Tag;

        private IID3v1 m_Id3v1Tag;

        private bool m_UsingV1;

        public MP3File(String filePath) {
            m_filePath = filePath;
            m_filename = new System.IO.FileInfo(filePath).Name;
            m_UsingV1 = ID3v1Helper.DoesTagExist(m_filePath);
            m_Id3v1Tag = ID3v1Helper.CreateID3v1(m_filePath);
            m_UsingV1 = !ID3v2Helper.DoesTagExist(m_filePath);
            m_Id3v2Tag = ID3v2Helper.CreateID3v2(m_filePath);
        }

        public String filePath {
            get { return m_filePath; }
            set { m_filePath = value; m_filename = new System.IO.FileInfo(filePath).Name; }
        }

        public String filename {
            get { return m_filename; }
        }

        public IID3v2 Id3v2Tag {
            get { return m_Id3v2Tag; }
            set { m_Id3v2Tag = value; }
        }

        public IID3v1 Id3v1Tag {
            get { return m_Id3v1Tag; }
            set { m_Id3v1Tag = value; }
        }

        public bool UsingV1
        {
            get { return m_UsingV1; }
            set { m_UsingV1 = value; }
        }

        public void reloadInfo() {
            m_Id3v1Tag = ID3v1Helper.CreateID3v1(m_filePath);
            m_Id3v2Tag = ID3v2Helper.CreateID3v2(m_filePath);
        }

        public void saveInfo() {
            m_Id3v1Tag.Save(m_filePath);
            m_Id3v2Tag.Save(m_filePath);

        }

        public void CopyTo(MP3File target) {
            target.Id3v1Tag = this.m_Id3v1Tag;
            target.Id3v2Tag = this.m_Id3v2Tag;
            target.filePath = this.filePath;
        }
	
    }
}
